home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.7 KB | 81 lines | [TEXT/GEOL] |
- Item 5267281 20-June-89 16:48
-
- From: ROSENSTEIN1 Rosenstein, Larry
-
- To: D2086 Efficient Field Svc, C Faith, PRT
-
- cc: MACAPP.TECH$ MACAPP Tech
-
- Sub: Re: Obj. Pascal
-
- (1) You cannot easily tell whether a method was called "normally" or via
- INHERITED. I suppose you could get the return address, find the JSR
- instruction that called the method, and see if the JSR was to the method
- dispatcher or directly to the method. (Every INHERITED call results in a
- direct JSR to the method.)
-
- I don't think this would be a good feature to have in Object Pascal; your code
- shouldn't care if a method is called directly or via INHERITED.
-
- It is hard to comment on your particular example, without knowing what the code
- does, but it sounds like TAbstract.DoSomething is intended to do something
- different from TConcrete.DoSomething. In that case, I would define a new
- method to do the work, and make TAbstract.DoSomething call ProgramBreak (when
- debugging code is turned on).
-
-
- (2) Segmentation does not determine whether a method call requires dispatching
- or not. In your example, the fact that MainMethod and AuxMethod are in the
- same segment doesn't change the fact that the compiler can't tell which
- implementation of AuxMethod is being called.
-
- The linker can (sometimes) tell which implementation will be called, and if you
- compile an optimized version it will change those method calls into direct
- JSRs. The most command case is when there is only one implementation of
- AuxMethod; clearly if there is one implementation it is easy to tell what the
- target of the call will be.
-
- In theory, any method call for which the linker can determine the exact method
- that will be called could be optimized to a direct JSR. For example, suppose
- the method TFoo.MainMethod is running and it calls SELF.AuxMethod. If TFoo has
- no subclasses then SELF must be a TFoo object. Therefore, the linker could
- change the SELF.AuxMethod call to a direct JSR.
-
- I don't know if the linker is smart enough to do this, however.
-
- I can say something about the Object Pascal dispatching scheme, as I understand
- it. (If things have changed, hopefully someone will post new info.) I will
- focus on the optimized scheme, since a shipping product would use that scheme.
-
- The method tables are organized by method. That is, there is a table for each
- method which contains all the implementations of that method. The table is
- normally searched linearly, so the average dispatching overhead depends on the
- number of implementations of a method.
-
- As I mentioned above, if there is only one implementation, then the overhead is
- 0 because the linker will change the call into a direct JSR. (When I say
- overhead, I mean extra time above and beyond a JSR.)
-
- I did some performance measurements a few months ago, and got a figure of about
- 80 microseconds of overhead for a method call. This was with a method having 6
- implementations.
-
- Object Pascal can sometimes do better than this, because it caches the class
- and code address each time a call is made to a method. If you call the method
- with and object of the same class, the second call will be much faster. My
- measurements indicated 31 microseconds of overhead if the method has been
- cached. (Each method has its own cache.)
-
- I also measured the overhead of a ROM trap at 31 microseconds.
-
- In general, Object Pascal imposes a dispatching overhead proportional to the
- "amount" of polymorphism you use. The dispatching overhead for the call x.Foo
- will be larger if you have 20 implementations of Foo. But presumably any of
- those implementations could be executed by that call. If you only have one
- implementation, then the overhead will be 0.
-
- Larry Rosenstein
-
-
-
-